package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;

public class Test {
    //花色
    private static final String[] SUITS = {"♥","♠","♣","♦"};
    //生成一副扑克牌：52张，4中花色，每种花色13个数字
    public static List<Card> buyCard(){
        List<Card> cards = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(SUITS[i],j);
                cards.add(card);
            }
        }
        return cards;
    }
    //洗牌
    public static List<Card> shuffle(List<Card> cards){
        Random random = new Random();
        for (int i = cards.size() - 1; i > 0 ; i--) {
            int j = random.nextInt(i);
            Card tmp = cards.get(i);
            cards.set(i,cards.get(j));
            cards.set(j,tmp);
        }
        return cards;
    }

    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println(cards);
        System.out.println("洗牌：");
        shuffle(cards);
        List<List<Card>> hand= new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        System.out.println(cards);
        //三个人每个人轮流揭牌五张
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);//每次都揭cards这副扑克牌的第一张
                hand.get(j).add(card);//揭到的牌发给谁
            }
        }
        System.out.println("第1个人的牌：");
        System.out.println(hand1);
        System.out.println("第2个人的牌：");
        System.out.println(hand2);
        System.out.println("第3个人的牌：");
        System.out.println(hand3);
        System.out.println("剩下的牌：");
        System.out.println(cards);





    }
}
